<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
    
    <?php
    // 连接数据库
    $conn=@mysql_connect("localhost","root","")  or die(mysql_error());
     mysql_query("SET NAMES UTF8");
    @mysql_select_db('guyueyan',$conn) or die(mysql_error());
    
    $i=0;$k=0;
    while(true)
        if(isset($_POST['ann'.$i++])){
            $k=1;
            break;
        }else if($i>=100){
            break;
        }
    
    $j=0;
    if($k==0){     //没有点击任何提交，那么是否点击了删除按钮
        while(true)
        if(isset($_POST['shan'.$j++])){
            $k=2;
            break;
        }else if($j>=100){
            break;
        }
    }
    if($k==0){
        echo "<script>alert('发生错误!');history.back();</script>";
        exit();
    }
    
    if($k==1){
         $i--;      //找到那个上传按钮被点击 ann$i
        $id = $_POST['ids'][$i];
        $url = $_POST['urls'][$i];
        /*echo $id.$url;*/

         $insert = "INSERT INTO pictures (name,user_id,type,content,url)SELECT name,user_id,type,content,'$url' FROM picture WHERE id=$id";

        if(mysql_query($insert)){
            $delete = "DELETE FROM picture WHERE id=$id";
            if(mysql_query($delete))
                echo "<script>alert('提交成功!');history.back();</script>";
            else
                echo "<script>alert('提交异常!');history.back();</script>";//审核成功，但未删除；
        }else
            echo "<script>alert('提交失败!');history.back();</script>";

            exit();
    }else if($k==2){
          $j--;      //找到那个上传按钮被点击 ann$i
        $id = $_POST['ids'][$j];
       
        $delete = "DELETE FROM picture WHERE id=$id";
        
        if(mysql_query($delete))
             echo "<script>alert('删除成功!');history.back();</script>";
        else
             echo "<script>alert('删除异常!');history.back();</script>";//审核成功，但未删除；
        
        
    }
   
    
?>
    
    
    
</body>
</html>